﻿package mortal.game.view.chat.chatPanel
{
    import __AS3__.vec.*;
    import com.mui.containers.*;
    import com.mui.containers.globalVariable.*;
    import flash.display.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.view.common.*;

    public class ChatMsgBox extends GBox
    {
        private const maxNum:int = 50;
        private var _hisVector:Vector.<HistoryMsg>;

        public function ChatMsgBox()
        {
            this._hisVector = new Vector.<HistoryMsg>;
            this.mouseEnabled = false;
            super.direction = GBoxDirection.VERTICAL;
            super.verticalGap = 2;
            return;
        }// end function

        public function addMsg(param1:String, param2:MsgTypeImpl) : void
        {
            var _loc_3:* = UIFactory.getUICompoment(HistoryMsg);
            _loc_3.updateValue(param1, param2);
            this.addChild(_loc_3);
            this.validateNow();
            this.updateDisplayList();
            this._hisVector.push(_loc_3);
            if (this._hisVector.length > this.maxNum)
            {
                _loc_3 = this._hisVector.shift();
                this.removeChild(_loc_3);
                _loc_3.dispose();
            }
            this.validateNow();
            this.updateDisplayList();
            return;
        }// end function

        public function isMaxLength() : Boolean
        {
            return this._hisVector.length == this.maxNum;
        }// end function

        public function getMsgAtIndex(param1:int) : HistoryMsg
        {
            return this._hisVector[param1];
        }// end function

        override public function get height() : Number
        {
            var _loc_4:DisplayObject = null;
            var _loc_5:int = 0;
            var _loc_1:Number = 0;
            var _loc_2:int = 0;
            var _loc_3:* = numChildren;
            while (_loc_2 < _loc_3)
            {
                
                _loc_4 = getChildAt(_loc_2) as DisplayObject;
                _loc_1 = _loc_1 + _loc_4.height;
                _loc_2++;
            }
            return _loc_1 + verticalGap * (this._hisVector.length - 1) + 5;
        }// end function

        public function clear() : void
        {
            var _loc_1:int = 0;
            var _loc_2:* = this.numChildren;
            _loc_1 = _loc_2 - 1;
            while (_loc_1 >= 0)
            {
                
                this.removeChildAt(_loc_1);
                _loc_1 = _loc_1 - 1;
            }
            _loc_1 = 0;
            while (_loc_1 < this._hisVector.length)
            {
                
                this._hisVector[_loc_1].dispose();
                _loc_1++;
            }
            this._hisVector = new Vector.<HistoryMsg>;
            return;
        }// end function

    }
}
